from config.all_paths import config_variable_path
from config.global_variable import JZKB
from utils.file_handling.txt_handling import extract_txt

def JZKBDataProcessing(data, res):
    """
    减重工作台数据处理
    """
    # 获取减重工作台数据
    if data.get('case_name') == '获取减重数据看板业务数据':
        freshTime = str(res.json()['data']['freshTime'])
        JZKB['freshTime'] = freshTime
        assignCount = str(res.json()['data']['assignCount'])
        JZKB['assignCount'] = assignCount
        claimedCount = str(res.json()['data']['claimedCount'])
        JZKB['claimedCount'] = claimedCount
        unClaimedCount = str(res.json()['data']['unClaimedCount'])
        JZKB['unClaimedCount'] = unClaimedCount
        invalidCount = str(res.json()['data']['invalidCount'])
        JZKB['invalidCount'] = invalidCount
        recentSevenEndCount = str(res.json()['data']['recentSevenEndCount'])
        JZKB['recentSevenEndCount'] = recentSevenEndCount
        noOpenCustomerCount = str(res.json()['data']['noOpenCustomerCount'])
        JZKB['noOpenCustomerCount'] = noOpenCustomerCount
        waitServiceCustomerCount = str(res.json()['data']['waitServiceCustomerCount'])
        JZKB['waitServiceCustomerCount'] = waitServiceCustomerCount
        serviceCustomerCount = str(res.json()['data']['serviceCustomerCount'])
        JZKB['serviceCustomerCount'] = serviceCustomerCount
        servicePauseCustomerCount = str(res.json()['data']['servicePauseCustomerCount'])
        JZKB['servicePauseCustomerCount'] = servicePauseCustomerCount
        serviceEndCustomerCount = str(res.json()['data']['serviceEndCustomerCount'])
        JZKB['serviceEndCustomerCount'] = serviceEndCustomerCount

    elif data.get('case_name') == '获取减重数据看板人群业绩数据':
        activeUserCount = str(res.json()['data']['activeUserCount'])
        JZKB['activeUserCount'] = activeUserCount
        normalUserClockCount = str(res.json()['data']['normalUserClockCount'])
        JZKB['normalUserClockCount'] = normalUserClockCount
        normalUserAvgCount = str(res.json()['data']['normalUserAvgCount'])
        JZKB['normalUserAvgCount'] = normalUserAvgCount
        normalClockTotalCount = str(res.json()['data']['normalClockTotalCount'])
        JZKB['normalClockTotalCount'] = normalClockTotalCount
        normalClockAvgCount = str(res.json()['data']['normalClockAvgCount'])
        JZKB['normalClockAvgCount'] = normalClockAvgCount
        sportUserCount = str(res.json()['data']['sportUserCount'])
        JZKB['sportUserCount'] = sportUserCount
        sportUserAvgCount = str(res.json()['data']['sportUserAvgCount'])
        JZKB['sportUserAvgCount'] = sportUserAvgCount
        sportClockTotalCount = str(res.json()['data']['sportClockTotalCount'])
        JZKB['sportClockTotalCount'] = sportClockTotalCount
        sportClockAvgCount = str(res.json()['data']['sportClockAvgCount'])
        JZKB['sportClockAvgCount'] = sportClockAvgCount

        actualOrderCount = str(res.json()['data']['actualOrderCount'])  # 实付订单数
        JZKB['actualOrderCount'] = actualOrderCount
        actualOrderCountPercent = str(res.json()['data']['actualOrderCountPercent'])  # 实付订单数环比上月
        JZKB['actualOrderCountPercent'] = actualOrderCountPercent
        actualPayTotal = str(res.json()['data']['actualPayTotal'])  # 实付总金额
        JZKB['actualPayTotal'] = actualPayTotal
        actualPayTotalPercent = str(res.json()['data']['actualPayTotalPercent'])  # 实付总金额环比上月
        JZKB['actualPayTotalPercent'] = actualPayTotalPercent
        firstOrderCount = str(res.json()['data']['firstOrderCount'])  # 首单数
        JZKB['firstOrderCount'] = firstOrderCount
        firstOrderCountPercent = str(res.json()['data']['firstOrderCountPercent'])  # 首单数环比上月
        JZKB['firstOrderCountPercent'] = firstOrderCountPercent
        firstPayTotal = str(res.json()['data']['firstPayTotal'])  # 首单总金额
        JZKB['firstPayTotal'] = firstPayTotal
        firstPayTotalPercent = str(res.json()['data']['firstPayTotalPercent'])  # 首单总金额环比上月
        JZKB['firstPayTotalPercent'] = firstPayTotalPercent
        newOrderCount = str(res.json()['data']['newOrderCount'])  # 新续数
        JZKB['newOrderCount'] = newOrderCount
        newOrderCountPercent = str(res.json()['data']['newOrderCountPercent'])  # 新续数环比上月
        JZKB['newOrderCountPercent'] = newOrderCountPercent
        newPayTotal = str(res.json()['data']['newPayTotal'])  # 新续总金额
        JZKB['newPayTotal'] = newPayTotal
        newPayTotalPercent = str(res.json()['data']['newPayTotalPercent'])  # 新续总金额环比上月
        JZKB['newPayTotalPercent'] = newPayTotalPercent
        newRenewRate = str(res.json()['data']['newRenewRate'])  # 新续率
        JZKB['newRenewRate'] = newRenewRate
        oldOrderCount = str(res.json()['data']['oldOrderCount'])  # 老续数
        JZKB['oldOrderCount'] = oldOrderCount
        oldOrderCountPercent = str(res.json()['data']['oldOrderCountPercent'])  # 老续数环比上月
        JZKB['oldOrderCountPercent'] = oldOrderCountPercent
        oldPayTotal = str(res.json()['data']['oldPayTotal'])  # 老续总金额
        JZKB['oldPayTotal'] = oldPayTotal
        oldPayTotalPercent = str(res.json()['data']['oldPayTotalPercent'])  # 老续总金额环比上月
        JZKB['oldPayTotalPercent'] = oldPayTotalPercent
        oldRenewRate = str(res.json()['data']['oldRenewRate'])  # 老续率
        JZKB['oldRenewRate'] = oldRenewRate

        extract_txt(config_variable_path, str(JZKB))

